package 异常处理;

import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//输入了相同的类出现了错误

  
public class ExceptionDemoLab4_3 {
	
	//计算奖金
	public void sCa(int y,double s){
		
		if(y<1)
		{
			System.out.println("奖金为： "+s);
		}
		else if(y<=3)
		{
			System.out.println("奖金为："+s*1.3);
		}
		else if(y<5)
		{
			System.out.println("奖金为："+s*1.5);	
		}
		else if(y>5)
		{
			System.out.println("奖金为："+s*1.5);
		}
		
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//获取当前年份
		  Calendar now = Calendar.getInstance();  
	       int y2=now.get(Calendar.YEAR);
		//输入入职年份
		try
		{
		String yi=args[0];
		Pattern pattern = Pattern.compile("[0-9]*"); 
        Matcher isNum = pattern.matcher(yi);
        if( !isNum.matches() ){
            throw new IllegalYearException();
        }
        String si=args[1];
        Matcher isNumi = pattern.matcher(yi);
        if( !isNumi.matches() ){
            throw new IllegalSalaryException("无效月工资");
        }
		//计算入职时间
        int y1=Integer.parseInt(yi);
        int te=y2-y1;//出现te为负数，和输入值问题
        if(y1>y2||y1<0)
        {
        	throw new IllegalYearException();
        }
		//输入月工资
		 int s1=Integer.parseInt(si);
		if(s1<500||s1<0)
		{
			throw new IllegalSalaryException("无效月工资");
		}
		ExceptionDemoLab4_3 Lab=new ExceptionDemoLab4_3();
		Lab.sCa(te, s1);
		}
		catch(IllegalYearException ex)
		{
			System.out.println(ex.getMessage());
		}
		catch(IllegalSalaryException ex)
		{
			System.out.println(ex.getMessage());
		}
		
	}
}


	